package com.leonzx.base.service.system;

import com.leonzx.base.dao.system.UserMenuTempDAO;
import com.leonzx.base.entity.system.UserMenuTemp;
import com.leonzx.base.service.BaseService;
import com.leonzx.base.utils.Constants;
import com.leonzx.base.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @Author:张勇
 * @Description:
 * @Date: 2018-06-19 17:50
 */
@Service
public class UserMenuTempService extends BaseService {
    @Autowired
    private UserMenuTempDAO userMenuTempDAO;

    /**
     * 人员权限临时表，有则更新，没有就插入
     *
     * @param userMenuTemp
     */
    public void saveOrUpdate(UserMenuTemp userMenuTemp) {
        Example example = new Example(UserMenuTemp.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("state", Constants.STATE_VAILD);
        criteria.andEqualTo("menuId", userMenuTemp.getMenuId());
        criteria.andEqualTo("userId", userMenuTemp.getUserId());
        Integer is = userMenuTempDAO.selectCountByExample(example);
        if (is > 0) {
            userMenuTempDAO.updateByExampleSelective(userMenuTemp, example);
        } else {
            userMenuTemp.setId(UUIDUtils.getUUID());
            userMenuTempDAO.insert(userMenuTemp);
        }
    }


}
